package asteroids;

import be.kuleuven.cs.som.annotate.*;

@Value 
public class Vector {
		
	private double[] vector;
	
	public Vector(int components) {
		vector = new double[components];
	}
	
	public double get(int index) {
		return vector[index];
	}
	
	public double getX() {
		return get(0);
	}
	
	public double getY() {
		return get(1);
	}
	
	public void set(int index, double value) {
		vector[index] = value;
	}
	
	public void setX(double value) {
		set(0, value);
	}
	
	public void setY(double value) {
		set(1, value);
	}
	
	public int getSize() {
		return vector.length;
	}
	
	public static Vector sum(Vector vector1, Vector vector2) {
		assert (vector1.getSize() == vector2.getSize());
		Vector result = new Vector(vector1.getSize());
		for (int i = 0; i < vector1.getSize(); i++) {
			result.set(i, vector1.get(i) + vector2.get(i));
		}
		return result;
	}
	
	public static Vector substract(Vector vector1, Vector vector2) {
		return sum(vector1, (multiply(vector2, -1)));
	}
	
	public static Vector multiply(Vector vector, double amount) {
		Vector result = new Vector(vector.getSize());
		for (int i = 0; i < vector.getSize(); i++) {
			result.set(i, vector.get(i) * amount);
		}
		return result;
	}
	
	public static double dotProduct(Vector vector1, Vector vector2) {
		assert (vector1.getSize() == vector2.getSize());
		double result = 0.0;
		for (int i = 0; i < vector1.getSize(); i++) {
			result += vector1.get(i) * vector2.get(i);
		}
		return result;
	}
	
	
}
